<template>
	<view class="content">
		<fui-text class="top" text="戒毒医疗" font-weight="600" :size="35"></fui-text>
		<fui-grid class="top">
			<fui-grid-item v-for="(item,index) in stateList" :key="index" @click="itemAction(item)">
				<view class="fui-grid__cell">
					<view class="cellBox">
						<image :src="item.icon" class="fui-icon" mode="widthFix"></image>
						<fui-text :text="item.title" font-weight="600" :size="28"></fui-text>
					</view>
				</view>
			</fui-grid-item>
		</fui-grid>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive,
		getCurrentInstance,
		onMounted
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app'
	const {
		proxy
	} = getCurrentInstance(); //获取上下文实例，ctx=vue2的this,=>proxy.tui
	const stateList = reactive([
	  {
	    title: "门诊医生站",
	    path: "/pages/index/outpatient/index",
	    icon: '/static/home/yishenzhang.png'
	  },
	  {
	    title: "门诊日志",
	    path: "/doctorStation",
	    icon: '/static/home/menzhenrizhi.png'
	  },
	  {
	    title: "门诊皮试",
	    path: "/doctorStation",
	    icon: '/static/home/pishi.png'
	  },
	  {
	    title: "门诊输液",
	    path: "/doctorStation",
	    icon: '/static/home/shuye.png'
	  },
	  {
	    title: "输液日志",
	    path: "/doctorStation",
	    icon: '/static/home/shuyerizhi.png'
	  },
	]);
	onLoad((options) => {
		// title.value = options.code
		// shuju.value = options.state
		console.log(options);
		let accessToken = uni.getStorageSync('accessToken');
		console.log(accessToken);
		if (!accessToken) {
			getAccessToken()
		}
	})
	
	const itemAction = (item) =>{
		console.log(item);
		uni.navigateTo({
			url: item.path
		})
	}
	
	const getAccessToken = () => {
		proxy.http.post('/system/auth/login', {
			brief: true,
			data: {
				username: "admin",
				password: "123456",
				rememberMe: true,
			}
		}).then(res => {
			uni.setStorageSync('accessToken',res);
			setTimeout(function() {
				getTagData()
			}, 100);
		}).catch(e => {
			console.log(e)
		})
	}
	const getTagData = () =>{
		proxy.http.get('/system/dict-data/simple-list', {
			brief: true,
			data: {}
		}).then(res => {
			console.log(res);
			uni.setStorageSync('tagData',res);
		}).catch(e => {
			console.log(e)
		})
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.top{
		margin-top: 30rpx;
	}
	.fui-grid__cell {
		width: 100%;
		height: 100%;
		padding: 30rpx;
		box-sizing: border-box;
		.cellBox{
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			width: 100%;
			height: 100%;
			border-radius: 20rpx;
			box-shadow: 0rpx 0rpx 8rpx rgba(0, 0, 0, 0.1);
		}
	}
	.fui-icon {
		width: 55rpx;
		height: 55rpx;
		margin-bottom: 16rpx;
	}
</style>